package com.ztesoft.ossup.report.dao;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.util.StringUtils;

import com.ztesoft.ossup.report.domain.ReportSub;
import com.ztesoft.ossup.report.domain.ReportSub_;

public interface ReportSubRepo extends JpaRepository<ReportSub, Long>, JpaSpecificationExecutor<ReportSub> {
	class ReportSpecifications {

		public static Specification<ReportSub> likeReportName(final String name) {
			return new Specification<ReportSub>() {
				@Override
				public Predicate toPredicate(Root<ReportSub> root, CriteriaQuery<?> criteriaQuery,
						CriteriaBuilder criteriaBuilder) {
							if (!StringUtils.isEmpty(name))
								return criteriaBuilder.like(root.get(ReportSub_.name), "%" + name + "%");
							return null;
						}
			};
		}
	}

	 List<ReportSub> findAllByReportId(Long id);
	
	 void deleteByReportId(Long reportId);

} 
